package co.yixiang.vod.config;

import co.yixiang.vod.service.VodTemplate;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * 阿里云视频点播自动配置类
 *
 * @description 配置文件添加：
 * vod:
 *   enable: true
 *   region: cn-shanghai
 *   access-key: your-access-key
 *   secret-key: your-secret-key
 *
 * 该配置类用于自动配置阿里云视频点播服务所需的Bean。
 * 通过@EnableConfigurationProperties注解导入VodProperties配置属性类
 */
@AllArgsConstructor
@EnableConfigurationProperties({ VodProperties.class })
public class VodAutoConfiguration {

	/**
	 * 注入的配置属性
	 */
	private final VodProperties properties;

	/**
	 * 创建阿里云视频点播操作模板对象
	 *
	 * @return VodTemplate 视频点播操作模板实例
	 * @see VodTemplate
	 * @see ConditionalOnMissingBean 仅当容器中不存在VodTemplate类型的Bean时才创建
	 * @see ConditionalOnProperty 仅当vod.enable=true时（默认为true）才创建该Bean
	 */
	@Bean
	@ConditionalOnMissingBean(VodTemplate.class)
	@ConditionalOnProperty(name = "vod.enable", havingValue = "true", matchIfMissing = true)
	public VodTemplate vodTemplate() {
		return new VodTemplate(properties);
	}

}